﻿//10.Write a program to calculate the sum 
//(with accuracy of 0.001): 1 + 1/2 - 1/3 + 1/4 - 1/5 + ...

using System;

namespace CalculateAccurateSum
{
    class AccurateSum
    {
        static void Main()
        {
            double n;
            double oldSum;
            double newSum = 1;
            double i = 2;
         
            do
            {
                n = 1 / i;

                oldSum = newSum;

                if (i % 2 == 0)
                {
                    newSum = oldSum + n;
                }
                else
                {
                    newSum = oldSum - n;
                }
                i++;
            }
            while (Math.Abs(newSum - oldSum) > 0.001);
            Console.WriteLine("The sum is: {0}",newSum);
        }
    }
}
